package com.spring.sunflower.common;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.spring.sunflower.R;
import com.spring.sunflower.bean.TaskItemBean;
import com.spring.sunflower.constant.Constant;

import java.util.List;

/**
 * Created by Kevin on 2021/8/24<br/>
 * <p>
 * Describe:<br/>
 */
public class TaskItemAdapter extends BaseQuickAdapter<TaskItemBean, BaseViewHolder> {
    private String gender;

    public TaskItemAdapter(int layoutResId, @Nullable List<TaskItemBean> data) {
        super(layoutResId, data);
        gender = SPUtils.getInstance().getString(Constant.KEY_GENDER, "1");
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, TaskItemBean taskItemBean) {
        ImageView ivCover = holder.getView(R.id.ivCover);
        Glide.with(getContext())
                .load(taskItemBean.getTaskImgPath())
                .placeholder(R.drawable.ic_placeholder)
                .into(ivCover);
        holder.setText(R.id.tvTitle, taskItemBean.getTaskName());
        holder.setText(R.id.tvDesc, taskItemBean.getTaskDesc());
        holder.setText(R.id.tvAward, taskItemBean.getAwardV());
        LinearLayout llAward = holder.getView(R.id.llAward);
        TextView tvFinished = holder.getView(R.id.tvFinished);
        if ("0".equals(taskItemBean.getCompleted())) {
            llAward.setVisibility(View.VISIBLE);
            tvFinished.setVisibility(View.GONE);
        } else {
            llAward.setVisibility(View.GONE);
            tvFinished.setVisibility(View.VISIBLE);
        }
        ImageView ivAward = holder.getView(R.id.ivAwardType);
        if ("1".equals(gender)) {
            Glide.with(getContext())
                    .load(R.drawable.ic_money)
                    .placeholder(R.drawable.ic_placeholder)
                    .into(ivAward);
        } else {
            Glide.with(getContext())
                    .load(R.drawable.ic_income_diamond)
                    .placeholder(R.drawable.ic_placeholder)
                    .into(ivAward);
        }
    }
}
